package org.longkey.portal
{
	import flash.display.DisplayObject;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	import flash.utils.setTimeout;
	
	import mx.binding.utils.BindingUtils;
	import mx.containers.Panel;
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	import mx.core.UITextField;
	import mx.core.mx_internal;
	import mx.managers.PopUpManager;
	
	import spark.components.Application;
	import spark.components.TitleWindow;

	use namespace mx_internal;
	
	/**
	 * 遮罩工具类。
	 * 非Flex里面的mask概念，而是仿Ext的一层半透明控件
	 * @author simon.fish
	 */
	public class MaskUtil {
		public static var target:DisplayObject;
		
		private static var _mask:Mask;
		
		private static function getMask():Mask{
			if(_mask == null)
				_mask = new Mask();
			return _mask;
		}
		
		public static function wait(msg:String = null, timeOut:Number = 0):void{
			if(target == null)
				return;
			getMask().apply(msg, Mask.WAIT);
			show(timeOut);
		}
		
		public static function info(msg:String, timeOut:Number = 3000):void{
			if(target == null)
				return;
			getMask().apply(msg, Mask.INFO);
			show(timeOut);
		}
		
		public static function error(msg:String, timeOut:Number = 3000):void{
			if(target == null)
				return;
			getMask().apply(msg, Mask.ERROR);
			show(timeOut);
		}
		
		public static function ok(msg:String, timeOut:Number = 3000):void{
			if(target == null)
				return;
			getMask().apply(msg, Mask.OK);
			show(timeOut);
		}
		
		private static function show(timeOut:Number):void{
			var m:Mask = getMask();
			PopUpManager.addPopUp(m, target, true);
			PopUpManager.centerPopUp(m);
			if(timeOut > 0){
				flash.utils.setTimeout(MaskUtil.hide, timeOut);
			}
		}
		
		public static function hide():void{
			PopUpManager.removePopUp(getMask());
		}
		
		
		
	}
}